home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / infor / wpj13.zip / READSET.C < prev    next >
C/C++ Source or Header  |  1993-03-02  |  6KB  |  263 lines

  1. /* ReadSet.C
  2.   Pete Davis 02/25/93
  3.  
  4.   Part of the install program for the Windows Programmer's Journal Vol 1 No 3
  5.  
  6.   Reads the SETUP.INF file on the SRCDRV disk to get all the installation
  7.   parameters. 
  8. */
  9.  
  10. #define MSFIX
  11. #define STRICT
  12. #include <windows.h>
  13. #include <malloc.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include "readset.h"
  17.  
  18. extern HANDLE         THandle;
  19. extern LInstInfo     InstallInfo;
  20. extern FAppList     CurApp;
  21. extern int             NumDisks;
  22.  
  23.  
  24. /* Get the installation setups as provided in the SETUP.INF on the first
  25.    disk of the application to install.
  26. */
  27.  
  28. BOOL GetInstallInfo(HWND hWnd, HANDLE hDlgModeless, char *SrcDrv) {
  29.  
  30.   char EMsg[40];
  31.   char SetFile[18];
  32.   HFILE SetUpFile;
  33.   char *FStart;
  34.   unsigned int ByteCount;
  35.  
  36.  
  37. /* Get it from our source drive */
  38.   strcpy(SetFile, SrcDrv);
  39.   strcat(SetFile, ":\\SETUP.INF\0");
  40.  
  41.  
  42.   SetUpFile = _lopen((LPSTR)SetFile, READ);
  43.  
  44.   /* If Problems with opening SETUP.INF file, then tell user */
  45.  
  46.   if (SetUpFile == HFILE_ERROR) {
  47.  
  48.     strcpy(EMsg, SetFile);
  49.     strcat(EMsg, " not found on Install Disk!\0");
  50.  
  51.     SetDlgItemText(hDlgModeless, 101, EMsg);
  52.  
  53.     strcpy(EMsg, "Installation Canceled! \0");
  54.  
  55.     SetDlgItemText(hDlgModeless, 102, EMsg);
  56.  
  57.     _lclose(SetUpFile);
  58.     return FALSE;
  59.   }
  60.  
  61.   InstallInfo->Classified=FALSE;
  62.  
  63.   FStart = (char *) LocalAlloc(LMEM_FIXED, 8192);
  64.   ByteCount = _lread(SetUpFile, FStart, 8192);
  65.  
  66.   /* We can't handle setup.inf files larger than 8k */
  67.  
  68.   if (ByteCount == 8192) {
  69.     strcpy(EMsg, "SETUP.INF file is too larger.\0");
  70.     SetDlgItemText(hDlgModeless, 101, EMsg);
  71.     strcpy(EMsg, "Installation Canceled!\0");
  72.     SetDlgItemText(hDlgModeless, 102, EMsg);
  73.     _lclose(SetUpFile);
  74.     LocalFree((HLOCAL) FStart);
  75.     return FALSE;
  76.   }
  77.  
  78.   _lclose(SetUpFile);
  79.  
  80.  
  81.   ScanFile(hWnd, FStart, ByteCount);
  82.   LocalFree((HLOCAL) FStart);
  83.   return TRUE;
  84. }
  85.  
  86.  
  87. /* Scan through the file and collect the necessary information */
  88.  
  89. void ScanFile(HWND hWnd, char *FStart, UINT ByteCount) {
  90.  
  91.   char *FEnd, *FCur;
  92.   int CLIdx;
  93.   char CurLine[100];
  94.   int Sect;
  95.  
  96.   FEnd = FStart + ByteCount;
  97.  
  98.   FCur = FStart;
  99.  
  100.   Sect = 1;
  101.  
  102.   /* This basically reads a line of text from the buffer */
  103.  
  104.   while (FCur < FEnd) {
  105.     CLIdx = 0;
  106.     while (*FCur != 13 & * FCur != 10) {
  107.       CurLine[CLIdx++] = *FCur++;
  108.     }
  109.     CurLine[CLIdx++] = '\0';
  110.     FCur += 2;
  111.  
  112.     /* Get any necessary info from line */
  113.     Sect = ProcessLine(hWnd, Sect, CurLine);
  114.   }
  115.  
  116.   return;
  117. }
  118.  
  119.  
  120. /* Process a single line */
  121.  
  122. int ProcessLine(HWND hWnd, int Sect, char *CurLine) {
  123.  
  124. FAppList TempApp;
  125. static ProgNo=0;
  126.  
  127.   /* Skip a comment */
  128.   if (*CurLine == ';') return(Sect);
  129.  
  130.   /* if we're in the first section, check for install specific data,
  131.      we'll check for file info later                                  */
  132.   if (Sect==1) {
  133.     if (!strnicmp(CurLine, "appname", 7)) {
  134.       appName(CurLine+8);
  135.     }
  136.     else if (!strnicmp(CurLine, "defpath", 7)) {
  137.       defPath(CurLine+8);
  138.     }
  139.     else if (!strnicmp(CurLine, "spacereq", 8)) {
  140.       spaceReq(CurLine+9);
  141.     }
  142.     else if (!strnicmp(CurLine, "grpfilename", 11)) {
  143.       grpFileName(CurLine+12);
  144.     }
  145.     else if (!strnicmp(CurLine, "grpdesc", 7)) {
  146.       grpDesc(CurLine+8);
  147.     }
  148.     /* This means we've started with the file data, so we
  149.        start going to section 2 for reading data.             */
  150.     else if (!strnicmp(CurLine, "infname", 7)) {
  151.       Sect = 2;
  152.     }
  153.   } /* if(Sect==1) */
  154.  
  155.   /* If we're in the second session, start counting up the number of files
  156.      and get all the variables.
  157.   */
  158.  
  159.   if (Sect == 2) {
  160.  
  161.     /* On a new file */
  162.     if(!strnicmp(CurLine,"infname",7)) {
  163.       ProgNo++; /* Program number */
  164.     
  165.       /* Add a node for our linked list */
  166.       THandle = GlobalAlloc(GMEM_MOVEABLE|GMEM_SHARE, sizeof(AppList));
  167.       TempApp = (FAppList) GlobalLock(THandle);
  168.  
  169.       /* Set defaults */
  170.       lstrcpy(TempApp->InFName, "\0");
  171.       lstrcpy(TempApp->OutFName, "\0");
  172.       lstrcpy(TempApp->OutPath, "\0");
  173.       lstrcpy(TempApp->FileDesc, "\0");
  174.       TempApp->DiskNum = 1;
  175.       TempApp->FileType = 2;
  176.  
  177.       /* Add node into our linked list */
  178.       TempApp->Next = InstallInfo->Apps;
  179.       InstallInfo->Apps = TempApp;
  180.       CurApp=TempApp;
  181.  
  182.       sinFName(CurLine+8);
  183.     }
  184.  
  185.     /* The rest of this is data for the current file */
  186.     else if(!strnicmp(CurLine,"outfname",8)) {
  187.       soutFName(CurLine+9);
  188.     }
  189.     else if(!strnicmp(CurLine,"outpath",7)) {
  190.       outPath(CurLine+8);
  191.     }
  192.     else if(!strnicmp(CurLine,"filedesc",8)) {
  193.       fileDesc(CurLine+9);
  194.     }
  195.     else if(!strnicmp(CurLine,"disknum",7)) {
  196.       diskNum(CurLine+8);
  197.     }
  198.     else if(!strnicmp(CurLine,"filetype",4)) {
  199.       isExec(CurLine+5);
  200.     }
  201.   } /* If Sect == 2 */
  202.   return(Sect);
  203.  
  204. }
  205.  
  206.  
  207. /* The rest of the routines are simply to copy the data from the
  208.    variables in the setup.inf to the structures in the program.
  209.    It's all pretty straight-forward.
  210. */
  211.  
  212. void appName(char *data) {
  213.   lstrcpy(InstallInfo->AppName, data);
  214. }
  215.  
  216. void classified(char *data) {
  217.   if (!strnicmp(data,"y",1)) InstallInfo->Classified = TRUE;
  218. }
  219.  
  220. void defPath(char *data) {
  221.   lstrcpy(InstallInfo->DefPath, data);
  222. }
  223.  
  224. void spaceReq(char *data) {
  225.  InstallInfo->TotSpaceReq = atol(data);
  226. }
  227.  
  228. void grpFileName(char *data) {
  229.   lstrcpy(InstallInfo->GrpFileName, data);
  230. }
  231.  
  232. void grpDesc(char *data) {
  233.   lstrcpy(InstallInfo->GrpDesc, data);
  234. }
  235.  
  236. void sinFName(char *data) {
  237.   lstrcpy(CurApp->InFName, data);
  238. }
  239.  
  240. void soutFName(char *data) {
  241.   lstrcpy(CurApp->OutFName, data);
  242. }
  243.  
  244. void outPath(char *data) {
  245.   lstrcpy(CurApp->OutPath, data);
  246. }
  247.  
  248. void fileDesc(char *data) {
  249.   lstrcpy(CurApp->FileDesc, data);
  250. }
  251.  
  252. void diskNum(char *data) {
  253.   CurApp->DiskNum = atoi(data);
  254.   if(CurApp->DiskNum > NumDisks) NumDisks = CurApp->DiskNum;
  255. }
  256.  
  257. void fileType(char *data) {
  258.   CurApp->FileType = atoi(data);
  259. }
  260.  
  261.  
  262.  
  263.